﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ParsingUrlsAndExtractingElements
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = "http://www.devbg.org/forum/index.php";
            string pattern = @"(?<protocol>http)://(?<server>(www.)?(\w|_|-|\.)+\.[\w]{1,3})(?<resource>(/|\w)+\.[\w]{1,3})";
            Regex regex = new Regex(pattern);
            Match match = regex.Match(text);

            while (match.Success)
            {
                Group protocol = match.Groups["protocol"];
                Console.WriteLine("[Protocol] = "+protocol.Value);
                Group server = match.Groups["server"];
                Console.WriteLine("[Server] = "+server.Value);
                Group resource = match.Groups["resource"];
                Console.WriteLine("[Resource] = "+resource.Value);
                match = match.NextMatch();
            }
            
        }
    }
}
